package Date;

import java.util.Scanner;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class Exercise02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名:>");
        String name = scanner.next();
        System.out.print("请输入密码:>");
        String password = scanner.next();
        System.out.print("请输入邮箱:>");
        String email = scanner.next();
        try {
            Check(name, password, email);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

    public static void Check(String name, String password, String email) {
        if (!(name != null && password != null && email != null)) {
            throw new RuntimeException("参数不能为空");
        }

        if (!(name.length() >= 2 && name.length() <= 4)) {
            throw new RuntimeException("用户名长度需要在2~4个字符之间!");
        }
        if (!(password.length() == 6 && isDigital(password))) {
            throw new RuntimeException("密码长度应为6位,并且为数字!");
        }

        int i = email.indexOf('@');
        int j = email.indexOf('.');
        if (!(i > -1 && j > i)) {
            throw new RuntimeException("邮箱需要包括@和.并且@需要在.之前!");
        }

        System.out.println("注册成功!");

    }

    public static boolean isDigital(String str) {
        char[] chars = str.toCharArray();
        for (int i = 0; i < str.length(); i++) {
            if (chars[i] < '0' || chars[i] > '9') {
                return false;
            }
        }
        return true;
    }
}
